package dice.sinanya.tools.checkdata.imal;

import com.forte.qqrobot.sender.MsgSender;
import dice.sinanya.db.monsterlist.InsertMonsterList;
import dice.sinanya.db.npclist.InsertNpcList;
import dice.sinanya.entity.EntityTypeMessages;

import static dice.sinanya.tools.checkdata.imal.GetZk.checkGroupActiveDelete;

public class LeaveGroup {
    static InsertMonsterList insertMonsterList = new InsertMonsterList();
    static InsertNpcList insertNpcList = new InsertNpcList();

    public static void leaveGroup(EntityTypeMessages entityTypeMessages, String groupId) {
        clear(groupId);
//        try {
//            entityTypeMessages.getMsgSender().SETTER.setDiscussLeave(groupId);
//            checkGroupActiveDelete(groupId);
//        } catch (Exception ignored) {
//
//        }

        try {
            entityTypeMessages.getMsgSender().SETTER.setGroupLeave(groupId, true);
            checkGroupActiveDelete(groupId);
        } catch (Exception ignored) {

        }

        try {
            entityTypeMessages.getMsgSender().SETTER.setGroupLeave(groupId, false);
            checkGroupActiveDelete(groupId);
        } catch (Exception ignored) {

        }
    }

    public static void leaveGroup(MsgSender msgSender, String groupId) {
        clear(groupId);
//        try {
//            msgSender.SETTER.setDiscussLeave(groupId);
//            checkGroupActiveDelete(groupId);
//        } catch (Exception ignored) {
//
//        }

        try {
            msgSender.SETTER.setGroupLeave(groupId, true);
            checkGroupActiveDelete(groupId);
        } catch (Exception ignored) {

        }

        try {
            msgSender.SETTER.setGroupLeave(groupId, false);
            checkGroupActiveDelete(groupId);
        } catch (Exception ignored) {

        }
    }

    public static void leaveGroup(MsgSender msgSender, long groupId) {
        clear(String.valueOf(groupId));
//        try {
//            msgSender.SETTER.setDiscussLeave(String.valueOf(groupId));
//            checkGroupActiveDelete(String.valueOf(groupId));
//        } catch (Exception ignored) {
//
//        }

        try {
            msgSender.SETTER.setGroupLeave(String.valueOf(groupId), true);
            checkGroupActiveDelete(String.valueOf(groupId));
        } catch (Exception ignored) {

        }

        try {
            msgSender.SETTER.setGroupLeave(String.valueOf(groupId), false);
            checkGroupActiveDelete(String.valueOf(groupId));
        } catch (Exception ignored) {

        }
    }

    private static void clear(String groupId) {
        insertMonsterList.deleteMonsterListByGroup(groupId);
        insertNpcList.deleteNpcListByGroup(groupId);
    }
}
